package com.car.controller;

import com.car.pojo.Job;
import com.car.pojo.Result;
import com.car.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RequestMapping("/jobs")
@RestController
public class JobController {

    @Autowired
    private JobService jobService;

    /**
     * 查询职位列表
     */
    @GetMapping
    public Result list(){
        log.info("查询全部职位数据");
        List<Job> jobList = jobService.findAll();
        return Result.success(jobList);
    }

    /**
     * 删除职位 - 使用路径参数
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据ID删除职位: {}", id);
        jobService.deleteById(id);
        return Result.success();
    }

    /**
     * 新增职位
     */
    @PostMapping
    public Result add(@RequestBody Job job){
        log.info("新增职位:{}", job);
        jobService.add(job);
        return Result.success();
    }

    /**
     * 根据ID查询职位
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据ID查询职位: {}", id);
        Job job = jobService.getById(id);
        return Result.success(job);
    }

    /**
     * 修改职位
     */
    @PutMapping
    public Result update(@RequestBody Job job){
        log.info("修改职位:{}", job);
        jobService.update(job);
        return Result.success();
    }
}